package inner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-05-18
 * Time: 9:26
 */
class OuterClass {
    private int data1 = 1;
    int data2 = 2;
    public static int data3 = 3;

    /**
     * 实例内部类
     * 1.如何获取实部内部类的对象
     * OuterClass.InnerClass innerClass = outerClass.new InnerClass();
     * 2.实例内部类当中 不能有静态的成员变量
     *   如果非要定义 那么只能是被static final修饰
     * 3.在实例内部类当中 如何访问外部类当中 相同的成员变量?
     * 在实例内部类当中 获取外部类的this ：OuterClass.this.data1
     */

    class InnerClass {

        public int data1 = 9;
        public int data4 = 4;
        int data5 = 5;
        public static final int data6 = 6;

        public void func() {
            System.out.println("InnerClass::func()");
            /*OuterClass outerClass = new OuterClass();
            System.out.println(outerClass.data1);*/

            System.out.println(OuterClass.this.data1);

            System.out.println(data1);
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
        }
    }

    public void test() {
        //static final int c = 0;
        System.out.println("OuterClass::test()");
        InnerClass innerClass = new InnerClass();
        innerClass.func();

        //final int SIZE = 10;//定义常量 常量是在程序编译的时候确定的
        //一旦初始化 就不能再进行修改
        //SIZE = 20;
    }

}

public class Test {

    public static void main(String[] args) {
        OuterClass outerClass = new OuterClass();
        OuterClass.InnerClass innerClass = outerClass.new InnerClass();
        innerClass.func();
    }
    public static void main1(String[] args) {

        OuterClass outerClass = new OuterClass();
        //System.out.println(outerClass.data1);

        OuterClass.InnerClass innerClass = outerClass.new InnerClass();

        OuterClass.InnerClass innerClass2 = new OuterClass().new InnerClass();

        //InnerClass innerClass = new InnerClass();
    }
}
